import Foundation

/// 日志打印类
class Log {
    
    /// 日志描述
    /// - Parameters:
    ///   - file: 文件路径
    ///   - function: 方法名
    ///   - line: 行数
    /// - Returns: 日志打印时间、位置信息
    private static func logDescription(_ file: String, _ function: String, _ line: Int) -> String {
        let fileName = (file as NSString).lastPathComponent
        let dformatter = DateFormatter()
        dformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let dateStr = dformatter.string(from: Date())
        return "\(dateStr) \(fileName)(\(line)) \(function):\n  "
    }
    
    /// 详细日志
    public static func verbose<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
        print("🔵 [VERBOSE] \(logDescription(file, function, line)) \(message)")
        #endif
    }
    
    /// 调试日志
    public static func debug<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
        print("🟢 [DEBUG] \(logDescription(file, function, line)) \(message)")
        #endif
    }
    
    /// 信息日志
    public static func info<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
        print("🟡 [INFO] \(logDescription(file, function, line)) \(message)")
        #endif
    }
    
    /// 警告日志
    public static func warning<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
        print("🟠 [WARNING] \(logDescription(file, function, line)) \(message)")
        #endif
    }
    
    /// 错误日志
    public static func error<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
        print("🔴 [ERROR] \(logDescription(file, function, line)) \(message)")
        #endif
    }
}


